package com.nanjia.boot.outboundorderview.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.nanjia.boot.common.result.PageResult;
import com.nanjia.boot.common.result.Result;
import com.nanjia.boot.outboundorderview.model.form.OutboundOrderViewForm;
import com.nanjia.boot.outboundorderview.model.query.OutboundOrderViewQuery;
import com.nanjia.boot.outboundorderview.model.vo.OutboundOrderViewVO;
import com.nanjia.boot.outboundorderview.service.OutboundOrderViewService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 出库单业务关联前端控制层
 *
 * @author 周洋
 * @since 2025-08-25 00:11
 */
@Tag(name = "出库单业务关联接口")
@RestController
@RequestMapping("/api/v1/outbound-order-view")
@RequiredArgsConstructor
public class OutboundOrderViewController  {

    private final OutboundOrderViewService outboundOrderViewService;

    @Operation(summary = "出库单业务关联分页列表")
    @GetMapping("/page")
//    @PreAuthorize("@ss.hasPerm('outbound_order_view:outbound-order-view:query')")
    public PageResult<OutboundOrderViewVO> getOutboundOrderViewPage(OutboundOrderViewQuery queryParams ) {
        IPage<OutboundOrderViewVO> result = outboundOrderViewService.getOutboundOrderViewPage(queryParams);
        return PageResult.success(result);
    }
    @Operation(summary = "新增出库单业务关联")
    @GetMapping("order")
//    @PreAuthorize("@ss.hasPerm('outbound_order_view:outbound-order-view:add')")
    public Result<Object> order(OutboundOrderViewQuery queryParams ) {
        return outboundOrderViewService.getOrder(queryParams);
    }


    @Operation(summary = "新增出库单业务关联")
    @PostMapping
//    @PreAuthorize("@ss.hasPerm('outbound_order_view:outbound-order-view:add')")
    public Result<Void> saveOutboundOrderView(@RequestBody @Valid OutboundOrderViewForm formData ) {
        boolean result = outboundOrderViewService.saveOutboundOrderView(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取出库单业务关联表单数据")
    @GetMapping("/{id}/form")
//    @PreAuthorize("@ss.hasPerm('outbound_order_view:outbound-order-view:edit')")
    public Result<OutboundOrderViewForm> getOutboundOrderViewForm(
        @Parameter(description = "出库单业务关联ID") @PathVariable Long id
    ) {
        OutboundOrderViewForm formData = outboundOrderViewService.getOutboundOrderViewFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改出库单业务关联")
    @PutMapping(value = "/{id}")
//    @PreAuthorize("@ss.hasPerm('outbound_order_view:outbound-order-view:edit')")
    public Result<Void> updateOutboundOrderView(
            @Parameter(description = "出库单业务关联ID") @PathVariable Long id,
            @RequestBody @Validated OutboundOrderViewForm formData
    ) {
        boolean result = outboundOrderViewService.updateOutboundOrderView(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除出库单业务关联")
    @DeleteMapping("/{ids}")
//    @PreAuthorize("@ss.hasPerm('outbound_order_view:outbound-order-view:delete')")
    public Result<Void> deleteOutboundOrderViews(
        @Parameter(description = "出库单业务关联ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = outboundOrderViewService.deleteOutboundOrderViews(ids);
        return Result.judge(result);
    }
}
